<template>
  <el-dialog
    :title="!dataForm.orderNumber ? this.$i18n.t('brand.add') : this.$i18n.t('brand.revise')"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="80%"
  >
    <el-form
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <div class="mod-order-orderInfo">
        <div class="content">
          <div class="order-number">
            <div class="num-cont">
              <el-form-item :label="this.$i18n.t('order.number') + ':'">
                <span class="text">{{dataForm.orderNumber}}</span>
              </el-form-item>
              <el-form-item>
                <el-steps
                  :active="stepsStatus"
                  align-center
                  :process-status="dataForm.status == 6 ? 'error':'wait'"
                >
                  <el-step
                    :title="this.$i18n.t('order.submitOrder')"
                    :description="dataForm.createTime"
                  ></el-step>
                  <el-step :title="this.$i18n.t('order.paid')" :description="dataForm.payTime"></el-step>
                  <el-step :title="this.$i18n.t('order.delivered')" :description="dataForm.dvyTime"></el-step>
                  <el-step
                    :title="this.$i18n.t('order.receivedGoods')"
                    :description="dataForm.finallyTime"
                  ></el-step>
                </el-steps>
              </el-form-item>
            </div>
          </div>
          <div class="order-state">
            <div class="state-cont">
              <div class="state-title">
                <el-form-item :label="this.$i18n.t('order.orderStatus') + ':'">
                  <template slot-scope="scope">
                    <el-tag
                      v-if="dataForm.status === 1"
                      size="small"
                      type="warning"
                    >{{$t('order.pendingPayment')}}</el-tag>
                    <el-tag
                      v-if="dataForm.status === 2"
                      size="small"
                      type="warning"
                    >{{$t('order.toBeShipped')}}</el-tag>
                    <el-tag
                      v-if="dataForm.status === 3"
                      size="small"
                      type="warning"
                    >{{$t('order.pendingReceipt')}}</el-tag>
                    <el-tag
                      v-if="dataForm.status === 4"
                      size="small"
                      type="warning"
                    >{{$t('order.toBeEvaluated')}}</el-tag>
                    <el-tag
                      v-if="dataForm.status === 5"
                      size="small"
                      type="success"
                    >{{$t('order.success')}}</el-tag>
                    <el-tag
                      v-if="dataForm.status === 6"
                      size="small"
                      type="danger"
                    >{{$t('order.fail')}}</el-tag>
                    <el-tag
                      v-if="dataForm.status === 7"
                      size="small"
                      type="danger"
                    >{{$t('group.waitGroup')}}</el-tag>
                  </template>
                </el-form-item>
              </div>
              <div class="order-info">
                <div class="order-details">
                  <div class="detail-title">
                    <img src="~@/assets/img/car.png" alt />
                    <span class="prompt">{{$t('order.deliveryMsg')}}</span>
                  </div>
                  <div class="detail-cont">
                    <div class="detail01">
                      <img src="~@/assets/img/address.png" alt />
                      <div class="text-width">
                        <!-- <span class="revise-addr" @click="changeAddr(dataForm.addrOrderId)">
                          <img src="~@/assets/img/revise.png" alt=""/>修改地址
                        </span>-->
                        <el-form-item :label="this.$i18n.t('publics.addressee') + ':'">
                          <span>{{dataForm.userAddrOrder.receiver}}</span>
                        </el-form-item>
                        <el-form-item :label="this.$i18n.t('publics.mobilePhone') + ':'">
                          <span>{{dataForm.userAddrOrder.mobile}}</span>
                        </el-form-item>
                        <el-form-item :label="this.$i18n.t('publics.deliveryAddr') + ':'">
                          <span>{{dataForm.userAddrOrder.province}}{{dataForm.userAddrOrder.city}}{{dataForm.userAddrOrder.area}}{{dataForm.userAddrOrder.addr}}</span>
                        </el-form-item>
                      </div>
                    </div>
                    <div class="detail01">
                      <img src="~@/assets/img/invoice.png" alt />
                      <span>{{$t('order.invoiceMsg')}}</span>
                    </div>
                  </div>
                </div>
                <div class="buyers">
                  <div class="detail-title">
                    <img src="~@/assets/img/buyer.png" alt style="margin-right:15px" />
                    <el-form-item
                      :label="this.$i18n.t('seckill.buyer') + ':'"
                      style="margin-top:22px"
                      label-width="44px"
                    >
                      <span>{{dataForm.nickName}}</span>
                    </el-form-item>
                  </div>
                  <div class="buyers-info">
                    <div class="detail02">
                      <img src="~@/assets/img/message.png" alt />
                      <div class="text-width">
                        <span>{{$t('order.compradorMsg')}}:</span>
                        <br />
                        <span>{{dataForm.remarks}}</span>
                      </div>
                    </div>
                    <!-- <div class="detail02">
                      <img src="~@/assets/img/remarks.png" alt="" width="18">
                      <div class="text-width">
                        <span>卖家备注：</span><br>
                        <span>给我加多点香菜</span>
                      </div>
                    </div>-->
                  </div>
                </div>
              </div>
              <div class="item-list">
                <el-table :data="dataForm.orderItems" border>
                  <el-table-column prop :label="this.$i18n.t('seckill.commodity')">
                    <template slot-scope="scope">
                      <img :src="resourcesUrl + scope.row.pic" width="100" height="100" />
                      <span>{{scope.row.prodName}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="price"
                    :label="this.$i18n.t('order.unitPrice')"
                    width="180"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span>{{scope.row.price}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="count"
                    :label="this.$i18n.t('order.quantity')"
                    width="180"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span>{{scope.row.prodCount}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="totalPrice"
                    :label="this.$i18n.t('order.totalPrice')"
                    width="180"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span>{{scope.row.productTotalAmount}}</span>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <div class="item-info">
                <el-form-item :label="this.$i18n.t('order.prodTotalPrice')">
                  <span class="text">￥{{dataForm.total}}</span>
                </el-form-item>
                <!-- <el-form-item label="店铺优惠:">
                <span class="text">￥15.00</span>
                </el-form-item>-->
                <!-- <el-form-item label="积分抵扣:">
                <span class="text">￥15.00</span>
                </el-form-item>-->
                <!-- <el-form-item label="发票费用:">
                <span class="text">￥15.00</span>
                </el-form-item>-->
                <el-form-item
                  :label="this.$i18n.t('order.shippingFees') + ':'"
                  v-if="dataForm.freightAmount"
                >
                  <span class="text">￥{{dataForm.freightAmount}}</span>
                </el-form-item>
                <el-form-item :label="this.$i18n.t('order.amountDue') + ':'">
                  <span class="text">￥{{dataForm.actualTotal}}</span>
                </el-form-item>
              </div>
            </div>
          </div>
          <div class="order-log">
            <div class="log-title">
              <span>{{$t('order.logs')}}</span>
            </div>
            <div class="log-cont">
              <el-form-item v-if="dataForm.createTime" label-width="10px">
                <span>{{dataForm.createTime}} {{dataForm.nickName}} {{$t('order.createOrder')}}</span>
              </el-form-item>
              <el-form-item v-if="dataForm.updateTime" label-width="10px">
                <span>{{dataForm.updateTime}} {{dataForm.nickName}} {{$t('order.orderUpdate')}}</span>
              </el-form-item>
              <el-form-item v-if="dataForm.payTime" label-width="10px">
                <span>{{dataForm.payTime}} {{dataForm.nickName}} {{$t('order.payment')}}</span>
              </el-form-item>
              <el-form-item v-if="dataForm.dvyTime" label-width="10px">
                <span>{{dataForm.dvyTime}} {{dataForm.nickName}} {{$t('order.deliverys')}}</span>
              </el-form-item>
              <el-form-item v-if="dataForm.finallyTime" label-width="10px">
                <span>{{dataForm.finallyTime}} {{dataForm.nickName}} {{$t('order.completed')}}</span>
              </el-form-item>
              <el-form-item v-if="dataForm.cancelTime" label-width="10px">
                <span>{{dataForm.cancelTime}} {{dataForm.nickName}} {{$t('order.cancelOrder')}}</span>
              </el-form-item>
            </div>
          </div>
        </div>
      </div>
    </el-form>
    <!-- 弹窗, 新增 / 修改 -->
    <devy-add v-if="devyVisible" ref="devyAdd" @refreshDataList="getDataList"></devy-add>
  </el-dialog>
</template>

<script>
// import AddOrUpdate from './order-addr'
import DevyAdd from './order-devy'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        orderId: 0,
        orderNumber: '',
        remarks: '',
        total: 0,
        actualTotal: 0,
        dvyType: '',
        status: 1,
        addrOrderId: 0,
        nickName: '',
        orderItems: [],
        orderTime: '',
        updateTime: '',
        payTime: '',
        dvyTime: '',
        finallyTime: '',
        cancelTime: '',
        userAddrOrder: {}
      },
      resourcesUrl: window.SITE_CONFIG.resourcesUrl,
      addOrUpdateVisible: false,
      devyVisible: false
    }
  },
  components: {
    // AddOrUpdate,
    DevyAdd
  },
  watch: {
    visible: function () {
      if (!this.visible) {
        this.devyVisible = false
        this.addOrUpdateVisible = false
      }
    }
  },
  computed: {
    stepsStatus: function () {
      if (this.dataForm.finallyTime) {
        return 4
      }
      if (this.dataForm.dvyTime) {
        return 3
      }
      if (this.dataForm.payTime) {
        return 2
      }
      if (this.dataForm.orderTime) {
        return 1
      }
    }
  },
  methods: {
    init (orderNumber) {
      this.dataForm.orderNumber = orderNumber || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
      })
      if (this.dataForm.orderNumber) {
        // 修改
        this.$http({
          url: this.$http.adornUrl(`/platform/order/orderInfo/${this.dataForm.orderNumber}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({ data }) => {
          this.dataForm = data
        })
      }
    },
    getDataList () {
      this.$http({
        url: this.$http.adornUrl(`/platform/order/orderInfo/${this.dataForm.orderNumber}`),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.dataForm = data
      })
    },
    // 表单提交
    dataFormSubmit () {
    },
    // // 发货
    // changeOrder (orderNumber) {
    //   this.devyVisible = true
    //   this.$nextTick(() => {
    //     this.$refs.devyAdd.init(orderNumber, this.dataForm.dvyId, this.dataForm.dvyFlowId)
    //   })
    // },
    // 修改备注
    changeRemarks () {
    },
    // 修改地址
    changeAddr (val) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(val)
      })
    }
  }
}
</script>


<style  lang="scss" scoped>
.mod-order-orderInfo {
  height: 100%;
  width: 100%;
  font: 14px Arial, "PingFang SC", "Hiragino Sans GB", STHeiti,
    "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
  color: #495060;

  .content {
    margin: 0 20px;
  }

  .content .steps {
    margin-top: 50px;
  }

  .order-number .number-text {
    font-weight: bold;
  }

  .order-number .text {
    font-size: 14px;
    color: #8a8a8a;
  }

  .order-state .state-title {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .title-left span {
    font-weight: bold;
  }

  .title-left .text {
    color: red;
  }

  .state-title .title-mid {
    display: flex;
    align-items: center;
  }

  .title-mid img {
    width: 18px;
    height: 18px;
  }

  .title-mid .mid-text {
    color: red;
  }

  .title-mid .text {
    color: #8a8a8a;
  }

  .content .order-state {
    position: relative;
    margin-top: 50px;
    border-bottom: 1px solid #e9eaec;
  }

  .order-state .order-info {
    width: 100%;
    border-top: 1px solid #e9eaec;
    margin: 50px 0;
    display: flex;
  }

  .order-info img {
    width: 18px !important;
    height: 18px !important;
    margin-right: 15px;
  }

  .order-info .detail-title {
    height: 50px;
    line-height: 50px;
    display: flex;
    align-items: center;
  }

  .order-info .order-details {
    width: 50%;
    border-right: 1px solid #e9eaec;
  }

  .order-info .detail-cont {
    position: relative;
  }

  .detail-cont .detail01 {
    display: flex;
    height: 100%;
    line-height: 25px;
    margin-top: 15px;
  }

  .detail01 .text-width {
    width: 100%;
  }

  .detail02 .text-width {
    width: 100%;
  }

  .detail-cont .revise-addr {
    color: #4395ff;
    position: absolute;
    top: 15px;
    right: 0;
    display: flex;
    align-items: center;
    cursor: pointer;
  }

  .order-info .detail-cont {
    border-top: 1px dashed #e9eaec;
    margin: 15px 20px 0 0;
  }

  .order-info .buyers {
    width: 50%;
    margin-left: 20px;
  }

  .buyers .buyers-info {
    border-top: 1px dashed #e9eaec;
    margin-top: 15px;
    position: relative;
  }

  .buyers .detail02 {
    display: flex;
    height: 100%;
    line-height: 25px;
    margin-top: 15px;
  }

  .buyers .revise-remarks {
    color: #4395ff;
    position: absolute;
    top: 15px;
    right: 0;
    display: flex;
    align-items: center;
    cursor: pointer;
  }

  .order-state .item-info {
    padding-left: 70%;
    margin: 25px 0;
  }

  .item-info span {
    margin-bottom: 15px;
    line-height: 30px;
  }

  .item-info .text {
    position: absolute;
    right: 0;
  }

  .item-info .amount {
    font-size: 18px;
    color: red;
  }

  .order-log .log-title {
    height: 50px;
    width: 100%;
    line-height: 50px;
    font-weight: bold;
    border-bottom: 1px dashed #e9eaec;
  }

  .order-log .log-cont {
    margin-top: 15px;
    color: #4395ff;
  }
}
</style>



